<?php
$path = 'instls/mods/' . basename(dirname(__FILE__));
$myPdo = DbUtils::createPdoInst();
$data = DbUtils::get($myPdo, 'pz2_sys', NULL, 't.script', 'ASC', NULL, NULL, NULL)->d;
?>
<style>
.list {
  border-left: 1px solid #ddd;
  border-top: 1px solid #ddd;
}
.list td {
  vertical-align: middle;
  text-align: left;
  padding: 2px; 
  border-right: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
}
.list td.nosort {
  background-color: #dababa;
  font-weight: bold;
  
}
.list tr.none td {
  background-color: #fff;
}
.list tr.rowodd td {
  background-color: #eee;
}
.list tr.roweven td {
  background-color: #fff;
}
.list tr.rowodd:hover td {
  background-color: #f4f3b2;
}
.list tr.roweven:hover td {
  background-color: #f4f3b2;
}
</style>
<button onclick="location.href='http://<?php echo URL . 'instls.php?mod=system&menu=systems'?>';">Create</button>
<table style="margin-top: 5px;" class="list" cellpadding=0 cellspacing=0>
  <tr>
    <td class="nosort" style="min-width: 50px;">Title</td>
    <td class="nosort" style="min-width: 250px;">Link</td>
    <td class="nosort" style="width: 40px;"></td>
  </tr>
  <?php foreach ($data as $idx => $obj) { ?>
    <tr class="<?php echo ($idx % 2 == 0) ? 'roweven' : 'rowodd'; ?>">
      <td><?php echo $obj->title; ?></td>
      <td>http://<?php echo URL . $obj->script; ?>.php</td>
      <td>
        <img style="cursor: pointer;" src="<?php echo $path; ?>/assets/imgs/edit.png" onclick="location.href='http://<?php echo URL . 'instls.php?mod=system&menu=systems&sid=' . $obj->id; ?>'"></img>
        <img style="cursor: pointer;" src="<?php echo $path; ?>/assets/imgs/delete24.png" onclick="remove('<?php echo htmlspecialchars(json_encode($obj)); ?>')"></img>
      </td>
    </tr>
  <?php } ?>
  <?php if (count($data) == 0) { ?>
    <tr class="none"><td colspan=3>None</td></tr>
  <?php } ?>
</table>

<script type="text/javascript" src="libs/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
  function remove(q) {
    var r = window.confirm('Click OK to Proceed?');
    if (r) {
      $.ajax({
        type: 'POST',
        url: '<?php echo $path . '/' . basename(__FILE__, '.php'); ?>.server.php',
        data: 'action=remove&q=' + encodeURIComponent(q),
        success: function(msg){
          try {
            JSON.parse(msg);
            location.href = 'http://<?php echo URL . 'instls.php?mod=systems&menu=systems'; ?>';
          } catch (ex) {
            alert( 'Error: ' + ex );
          }
        }
      });
    }
  }
</script>